<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/14
 * Time: 13:38
 */

namespace app\home\controller;


use cmf\controller\BaseController;
use app\portal\service\PostService;
use think\Db;

class NewarticleController extends BaseController
{

     public function index(){

         $pageId      = $this->request->param('id', 0, 'intval');

        $article=Db::name("portal_post")->where('id',$pageId)->order('id', 'DESC')->find();
         $this->assign('article', $article);
        $cid= $article['post_type'];
         $where = [
             'post_type'      => $cid,
             'published_time' => [['< time', time()], ['> time', 0]],
             'post_status'    => 1,
             'delete_time'    => 0,
             'id '            => ['<', $pageId]
         ];
         $pre= Db::name("portal_post")->where($where)->order('id', 'DESC')->find();
         if (empty($pre)){
             $pre['post_title']="没有了";
             $pre['url']="javascript:viod()";
         }else{
             $pre['url']="http://".$_SERVER['SERVER_NAME']."/public/portal/new/article/id/".$pre['id']."/cid/".$cid;
         }
         $this->assign('pre', $pre);
         $where = [
             'post_type'      => $cid,
             'published_time' => [['< time', time()], ['> time', 0]],
             'post_status'    => 1,
             'delete_time'    => 0,
             'id '            => ['>', $pageId]
         ];
         $next=Db::name("portal_post")->where($where)->order('id', 'DESC')->find();

         if (empty($next)){
             $next['post_title']="没有了";
             $next['url']="javascript:viod()";
         }else{
             $next['url']="http://".$_SERVER['SERVER_NAME']."/public/portal/new/article/id/".$next['id']."/cid/".$cid;
         }
         $this->assign('next', $next);
         // print_r($next);exit;

         return $this->fetch(":articles");
     }

}